package com.fas.system.service.impl;

import com.fas.common.core.domain.AjaxResult;
import com.fas.system.domain.FasFacilitiesTypeSpec;
import com.fas.system.mapper.FasFacilitiesTypeSpecMapper;
import com.fas.system.service.IFasFacilitiesTypeSpecService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FasFacilitiesTypeSpecServiceImpl implements IFasFacilitiesTypeSpecService {

    @Resource
    private FasFacilitiesTypeSpecMapper fasFacilitiesTypeSpecMapper;

    @Override
    public List<FasFacilitiesTypeSpec> findByFacilityId(FasFacilitiesTypeSpec fasFacilitiesTypeSpec) {
        return fasFacilitiesTypeSpecMapper.findByFacilityId(fasFacilitiesTypeSpec);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addFasFacilitiesTypeSpec(FasFacilitiesTypeSpec fasFacilitiesTypeSpec) {
        String specName = fasFacilitiesTypeSpec.getSpecName();
        int existsName = fasFacilitiesTypeSpecMapper.existsSpecName(specName);
        if (existsName > 0){
            return AjaxResult.error("规格名称已存在，请重新输入！");
        }
        int count = fasFacilitiesTypeSpecMapper.addFasFacilitiesTypeSpec(fasFacilitiesTypeSpec);
        return count > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int editFasFacilitiesTypeSpec(FasFacilitiesTypeSpec fasFacilitiesTypeSpec) {
        return fasFacilitiesTypeSpecMapper.editFasFacilitiesTypeSpec(fasFacilitiesTypeSpec);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFasFacilitiesTypeSpec(String id) {
        return fasFacilitiesTypeSpecMapper.deleteFasFacilitiesTypeSpec(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int enableSpec(FasFacilitiesTypeSpec fasFacilitiesTypeSpec) {
        return fasFacilitiesTypeSpecMapper.enableSpec(fasFacilitiesTypeSpec);
    }
}
